package com.wclass.controller.app;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.wclass.common.ReturnObject;
import com.wclass.entity.UserStatisticsBill;
import com.wclass.interceptor.BaseContextHandler;
import com.wclass.service.IUserStatisticsBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户统计 前端控制器
 * </p>
 *
 * @author SEN
 * @since 2019-01-07
 */
@Api(description = "用户统计")
@RestController
@RequestMapping("/userStatisticsBill")
public class UserStatisticsBillController {
    @Autowired
    private IUserStatisticsBillService iUserStatisticsBillService;

    @ApiOperation("获取本用户统计")
    @RequestMapping(value = "/getUserStatisticsList", method = RequestMethod.POST)
    public ReturnObject<List<UserStatisticsBill>> getUserStatisticsList(@ApiParam("统计类型（0：日统计，1：周统计，：2月统计）") @RequestParam Integer type,
                                                                        @ApiParam("获取条数") @RequestParam Integer num) {
        EntityWrapper<UserStatisticsBill> ew = new EntityWrapper<>();
        ew.orderBy("crt_time", false);
        ew.eq("user_id", BaseContextHandler.getUserID());
        ew.eq("type", type);
        Page<UserStatisticsBill> obj = iUserStatisticsBillService.selectPage(new Page<>(1, num), ew);
        return new ReturnObject<>(0, "获取成功", obj.getRecords());
    }

}

